package com.example.game_forum.service;

import com.example.game_forum.dto.TPostContentDto;
import com.example.game_forum.dto.TPostDto;
import com.example.game_forum.dto.TPostTitleDto;
import com.example.game_forum.repository.TPostRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TPostService {

    @Autowired
    private TPostRepository postRepository;

    public List<TPostTitleDto> getPostTitlesByPostType(String postType) {
        return postRepository.selectPostTitlesByPostType(postType);
    }

    public List<TPostTitleDto> searchPostsByTitle(String title){
        return postRepository.selectPostTitlesByTitle(title);
    }

    public List<TPostTitleDto> getPostTitleByUserId(String userId) {
        return postRepository.selectPostTitlesByUserid(userId);
    }

    public TPostContentDto getPostContentById(String postId) {
        return postRepository.selectPostContentById(postId);
    }
    @Transactional
    public void addPost(TPostDto postDto) {
        postRepository.insertPost(postDto);
    }

    @Transactional
    public void updatePost(String postId,TPostDto postDto) {
        postRepository.updatePost(postId, postDto);
    }

    @Transactional
    public void deletePost(String postId) {
        postRepository.deletePost(postId);
    }
}
